﻿using ArtMath.CommonType;
using ArtMath.Core.Helper;
using System;
using System.ComponentModel;

namespace ArtMath.Data
{
    [Serializable]
    public class AngleStringX : PadStringX
    {
        public AngleStringX(SketchPad pad) : base(pad)
        {
            LinkedPad.AngleUnitChanged += onAngleUnitChanged;
        }
        public AngleStringX(SketchPad pad, string expression) : this(pad)
        {
            SetExpression(expression, false);
        }
        public AngleStringX(SketchPad pad, double value) : this(pad)
        {
            SetExpression(value, false);
        }
        ~AngleStringX()
        {
            LinkedPad.AngleUnitChanged -= onAngleUnitChanged;
        }
        [Browsable(false)]
        public double RadValue
        {
            get
            {
                if (LinkedPad.AngleUnit == AngleUnit.Degree) return Value * Angle.DToR;
                return Value;
            }
        }
        [Browsable(false)]
        public double DegreeValue
        {
            get
            {
                if (LinkedPad.AngleUnit == AngleUnit.Radian) return Value * Core.Helper.Angle.RToD;
                return Value;
            }
        }
        void onAngleUnitChanged()
        {
            double newVal = Value * (LinkedPad.AngleUnit == AngleUnit.Degree ? Core.Helper.Angle.RToD : Angle.DToR);
            SetExpression(newVal, false);
        }
        //public override string ToString()
        //{
        //    string str = base.ToString();
        //    if (Pad.AngleUnit == AngleUnit.Degree)
        //    {
        //        str += "°";
        //    }
        //    return str;
        //}
    }
}
